package com.ggh.jinjilive.ui.mine.personal.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.RecyclerView;

import com.blankj.utilcode.util.ScreenUtils;
import com.bumptech.glide.Glide;
import com.ggh.jinjilive.R;
import com.ggh.jinjilive.databinding.ItemPersonalDataBinding;
import com.ggh.jinjilive.databinding.ItemPersonalDataHeadBinding;
import com.ggh.jinjilive.listener.AddItemOnClickListener;
import com.ggh.jinjilive.mobile.live.im.CustomMessage;
import com.ggh.jinjilive.mobile.mine.video.PersonalVideoList;

import java.util.ArrayList;
import java.util.List;

public class PersonalDataAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private Context mContext;

    public PersonalDataAdapter(Context mContext){
        this.mContext = mContext;

    }

    public static final int TYPE_ITEM = 0;
    public static final int TYPE_FOOTER = 1;




    private List<PersonalVideoList> personalVideoListList;

    /**
     * 添加视频信息
     * @param personalVideoListList
     */
    public void addCustomMessage(List<PersonalVideoList> personalVideoListList){
        this.personalVideoListList = personalVideoListList;
        notifyDataSetChanged();
    }

    /**
     * 添加视频信息
     * @param personalVideoListList
     */
    public void setList(List<PersonalVideoList> personalVideoListList){
        if(null == this.personalVideoListList){
            this.personalVideoListList = personalVideoListList;
        }else {
            this.personalVideoListList.addAll(personalVideoListList);
        }
        notifyDataSetChanged();
    }


    private AddItemOnClickListener addItemOnClickListener;
    public void setAddItemOnClickListener(AddItemOnClickListener addItemOnClickListener) {
        this.addItemOnClickListener = addItemOnClickListener;
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        if (viewType == TYPE_ITEM) {
            ItemPersonalDataHeadBinding binding = DataBindingUtil.inflate(LayoutInflater.from(parent.getContext()), R.layout.item_personal_data_head, parent, false);
            return new LiveNavHolder(binding);
        }else {
            ItemPersonalDataBinding binding = DataBindingUtil.inflate(LayoutInflater.from(parent.getContext()), R.layout.item_personal_data, parent, false);
            return new ItemViewHolder(binding);
        }
    }

    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder recyclerViewholder,final int position) {
        if (recyclerViewholder instanceof LiveNavHolder) {//头部
            LiveNavHolder holder = (LiveNavHolder) recyclerViewholder;

        }else if(recyclerViewholder instanceof ItemViewHolder){
            ItemViewHolder holder = (ItemViewHolder) recyclerViewholder;
            PersonalVideoList personalVideoList = personalVideoListList.get(position);
            if(null != personalVideoList){
                //图片加载
                Glide.with(holder.binding.RoundedImageView).load(personalVideoList.getCover()).into(holder.binding.RoundedImageView);
                //人数
                holder.binding.tvNumber.setText(personalVideoList.getLook_num() + "");
                //名称
                holder.binding.tvName.setText(personalVideoList.getTitle());
                //
            }
        }

    }

    @Override
    public int getItemCount() {
        return null == personalVideoListList ? 0 : personalVideoListList.size();
    }


    @Override
    public int getItemViewType(int position) {
        if (position == 0) {
            return TYPE_ITEM;
        }else {
            return TYPE_FOOTER;
        }
    }


    class LiveNavHolder extends RecyclerView.ViewHolder {
        ItemPersonalDataHeadBinding binding;
        public LiveNavHolder(@NonNull ItemPersonalDataHeadBinding binding) {
            super(binding.getRoot());
            this.binding = binding;
        }
    }

    class ItemViewHolder extends RecyclerView.ViewHolder {
        ItemPersonalDataBinding binding;
        public ItemViewHolder(@NonNull ItemPersonalDataBinding binding) {
            super(binding.getRoot());
            this.binding = binding;
            ViewGroup.LayoutParams params =  binding.flVideo.getLayoutParams();
            params.height = ScreenUtils.getScreenWidth() / 2 ;
            binding.flVideo.setLayoutParams(params);
            binding.flVideo.setBackgroundResource(R.drawable.bg_5_f);
        }
    }




}